<?php

/* 
 * XMLParser class
 * Author: Sergi Juanola korcholis [at] gmail [dot] com
 * Parses an XML file and gets its values easily using a key or an associative array of keys.
 * If you pass a key (as string), it returns a value (as string).
 * If you pass an array, it populates the array and then returns it.
 * Example:
 * $xml = new XMLParser($this->configFile);
 * $values = array("hostname"=>"","username"=>"","password"=>"","database"=>"");
 * $values = $xml->getValue($xml);
 */ 

class XMLParser
{
    private $xml;
    public function __construct($fileOrUrl)
    {
        $this->xml = simplexml_load_file($fileOrUrl) or die("xml could not be loaded");
    }
    
    public function getValue($key)
    {
        if(is_array($key))
            return $this->getMultipleValues($key);
        var_dump($this->xml);
        return $this->xml->$key;
    }
    
    private function getMultipleValues($array)
    {
        foreach($array as $key=>$value)
        {
            $array[$key] = $this->xml->$key;
        }
        return $array;
    }
    
    public function __destruct()
    {
    }
}
?>
